package ModelLayer;

import java.lang.IllegalArgumentException;
/**
 * This class is part of an address book system. It's an aggregation of class LoanCon, and contains Loan
 * data for loans contained within the collection. 
 *
 * The purpose of this class is to supply information to the ControlLayer. 
 * 
 * @author Anders A.P, Anna K., Danny M.P., Jakob K., Mie P.  
 * @version 1.0
 */
public class Loan
{
    private static int  classID = 0;
    private int         id;
    private String      fromDate;
    private String      toDate;
    private boolean     state;
    private boolean     isTooLate;
    private Person      person;
    private Copy        copy;
    /**
     * Constructs in instance of class Loan, incrementing the classID field and takin the following parameters:
     * 
     * @param   fromDate    Loan beginning as a String represented as a date.
     * @param   toDate      Loan estimated end as a String represented as a date.
     * @param   p           A Person object
     * @param   c           A Copy object
     */
    public Loan(String fromDate, String toDate, Person p, Copy c)
    {
        classID++;
        id = classID;
        setFromDate(fromDate);
        setToDate(toDate);
        state = true;
        isTooLate = false;
        person = p;
        copy = c;
    }
    
    /**
     * Sets new information in the fromDate field, taking the following parameters:
     *
     * @param   s           New fromDate as a String, not blank.
     * @throw   Exception   If String is blank.
     */
    public void setFromDate(String s)
    {
        if(s.length() <= 1) {
            throw new IllegalArgumentException("From date not valid");
        }
        else {
            fromDate = s;
        }
    }
    
    /**
     * Sets new information in the toDate field, taking the following parameters:
     *
     * @param   toDate      New toDate as a String, not blank.
     * @throw   Exception   If String is blank.
     */
    public void setToDate(String s)
    {
        if(s.length() <= 1) {
            throw new IllegalArgumentException("To date not valid");
        }
        else {
            toDate = s;
        }
    }

    /**
     * Sets new information in the state field, taking the following parameters:
     *
     * @param   change      New state as a boolean.
     */    
    public void setState(boolean change)
    {
        state = change;
    }

    /**
     * Sets new information in the isTooLate field, taking the following parameters:
     *
     * @param   toDate      New isTooLate as a boolean.
     */    
    public void setIsTooLate(boolean change)
    {
        isTooLate = change;
    }
    
    /**
     * Returns the value of the field id to the caller.
     *
     * @return  id  Returns Loan id.
     */  
    public int getID()
    {
        return id;
    }

    /**
     * Returns the value of the field fromDate to the caller.
     *
     * @return  fromDate    Returns Loan fromDate.
     */      
    public String getFromDate()
    {
        return fromDate;
    }

    /**
     * Returns the value of the field toDate to the caller.
     *
     * @return  toDate  Returns Loan toDate.
     */      
    public String getToDate()
    {
        return toDate;
    }

    /**
     * Returns the value of the field state to the caller.
     *
     * @return  state   Returns Loan state.
     */      
    public boolean getState()
    {
        return state;
    }

    /**
     * Returns the Person object associated to Loan to the caller.
     *
     * @return  Person  Returns Person object associated to Loan.
     */      
    public Person getPerson()
    {
        return person;
    }

    /**
     * Returns the Copy object associated to Loan to the caller.
     *
     * @return  Copy    Returns Copy object associated to Loan.
     */     
    public Copy getCopy()
    {
        return copy;
    }
}
